﻿using DataTurnClient.Enum;
using DataTurnClient.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataTurnClient.Server
{
    public class Ding<T>
    {
        public String Code;

        public Result<T> Send(T Models)
        {
            Result<T> msg = new Result<T>
            {
                Code = 200,
                Message = "成功",
                Success = true
            };
            Post<T> p = new Post<T>
            {
                Post_url = Code,
                Post_data = Models,
                Post_mode = DType.RequestType.Post,
            };
            msg = p.PostSend();
            return msg;
        }
    }
    public class DingSend
    {
        /// <summary>
        /// 钉钉机器人
        /// </summary>
        /// <param name="url">机器人url</param>
        /// <param name="safeCode">安全口令</param>
        /// <param name="message">发送的markdown格式文本</param>
        /// <returns></returns>
        public static Result<DingMsg> MsgSend(string url, string safeCode, string message)
        {
            Result<DingMsg> msg = new Result<DingMsg>();
            Ding<DingMsg> ding = new Ding<DingMsg>
            {
                Code = url,
            };
            msg = ding.Send(new DingMsg
            {
                MsgType = "markdown",
                MarkDown = new DingMsgMarkDown
                {
                    Title = safeCode,
                    Text = message,
                }
            });
            return msg;
        }
    }
}
